package com.syxd.service.impl;

import com.syxd.common.entity.WebResult;
import com.syxd.dao.SysConfigDao;
import com.syxd.dto.SysSettingDto;
import com.syxd.entity.SysSettingEntity;
import com.syxd.service.SysConfigService;
import com.syxd.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
@Transactional
public class SysConfigServiceImpl implements SysConfigService {
    @Autowired
    SysConfigDao sysConfigDao;
    @Autowired
    SysUserService sysUserService;

    @Override
    public WebResult update(SysSettingDto sysSettingDto, HttpServletRequest request) {
        if (sysSettingDto.getSettingDate() != null) {
            SysSettingEntity sysSettingEntity = new SysSettingEntity();
            sysSettingEntity.setId(1);
            sysSettingEntity.setUpdateTime(new Date());
            sysSettingEntity.setSettingDate(sysSettingDto.getSettingDate());
            Integer userId = Integer.valueOf((String) sysUserService.getInfoFromToken(request, "userId").getData());
            sysSettingEntity.setUpdateBy(userId);
            sysConfigDao.updateById(sysSettingEntity);
            return new WebResult();

        }
        return new WebResult().error();


    }

}
